<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><!DOCTYPE html>
<%String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/"; %>
<html lang="en">
<head>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.messager.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap.min.js"></script>
<jsp:include page="../admin_head.jsp">
	<jsp:param value="管理员登录" name="title" />
</jsp:include>

</head>
<body>
	<div class="container-fluid">
		<div class="row">
			<div class="col-md-2"></div>
			<div class="col-md-8">
				<div class="panel panel-success" align="center">
					<div class="panel-heading">
						<h3 class="panel-title">登录-课堂评价系统</h3>
					</div>
					<div class="panel-body">
							<div class="form-group">
								<label for="username"> <B> 用户名： </B></label> 
								<input id="username" type="text" name="username" class="form-control" style="width: 180px" />
							</div>
							<div class="form-group">
								<label for="password"> <B> 密码： </B></label> 
								<input id="password" type="password" class="form-control" name="password" style="width: 180px" />
							</div>
							<button onclick="login()" class="btn btn-default" style="width: 180px"> <B> 登录 </B> </button>
					</div>
				</div>
			</div>
			<div class="col-md-2"></div>
		</div>
	</div>
<script type="text/javascript">
	var baseUrl = "<%= baseUrl%>";
	window.onload = function(){
	}
	function isNum(num){
		var re = /^[1-9]+[0-9]*]*$/; //判断正整数  //判断字符串是否为数字/^[0-9]+.?[0-9]*$/ 
		if (!re.test(num)) {
			return false;
		}else{
			return true;
		}
	}
	
	//登录
	function login(){
		var username = $("#username").val();
		var password = $("#password").val();
		$.ajax({
			type:"POST",
			url: baseUrl + "user/login.action",
			data:{username:username,password:password},
			success:function(res){
				if(isNum(res)){
					window.location.href = baseUrl + "user/userlist.action?userId=" + res;
				}else{
					$.messager.popup("登录失败!请确认帐号、密码是否正确！");
				}
			},
			error:function(res){//1由于返回的对象不符合json格式，所以跳转到此处 2 若使用json对象返回，则中文显示成问号（未解决）
				if(res.status == 200){//成功登录后处理
					$.messager.popup("登录成功!");
					window.location.href = baseUrl + "user/userlist.action";
				}
			}
		});
	}
	
</script>
</body>
</html>